var names = ['青鸟', '朱砂', '凤凰', '赤龙']
cc.Class({
    extends: require('UI-PanelWindow'),

    properties: {
        lockedPlane: require('SelectPlayer'),
        launcher: require('SkillLauncher'),
        content: cc.Node,
        coin: cc.Label,
        planeName: cc.Label,
        forceLabel: require('JumpText')
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        this._super();
        this.arr = [0, 5000, 20000, 80000];
        this.content.runAction(cc.scaleTo(0.2, 1));
    },

    start() {

    },
    setOptions(options) {
        let planeId = options.plane;
        this.money = this.arr[planeId]
        this.launcher.setSkillParentNode(this.launcher.node, true);
        this.lockedPlane.setPlaneId(planeId);
        this.coin.string = this.money;
        this.planeName.string = names[planeId]
        var tiaojian = global.Data.unlock[planeId];
        var isReachOne = global.Data.coin >= tiaojian.coin ? true : false;
        var whichLevel = 0;
        global.Data.plane.gate.forEach(element => {
            if (element == 1) whichLevel++;
        });
        var isReachTwo = whichLevel >= tiaojian.gate ? true : false;
        var isReachThree = global.Data.inviteCount >= tiaojian.invite ? true : false;
        cc.find('content/term/tiaojian1', this.node).getComponent(cc.Label).string = tiaojian.coin + '(' + (isReachOne ? '已达成' : '未达到') + ')'
        cc.find('content/term/tiaojian2', this.node).getComponent(cc.Label).string = '通关第' + tiaojian.gate + '关' + '(' + (isReachTwo ? '已达成' : '未达到') + ')'
        cc.find('content/term/tiaojian3', this.node).getComponent(cc.Label).string = '邀请' + tiaojian.invite + '个好友' + '(' + (isReachThree ? '已达成' : '当前:'+global.Data.inviteCount+'/'+tiaojian.invite) + ')'
        cc.find('content/term/tiaojian3/share', this.node).active = !isReachThree;
        this.forceLabel.setText(global.Config.ForceValue[planeId])
        this.options = options
    },

    btnUnlock() {
        var self = this
        this.httpGet('/game/gameUser', 'plane.buyPlane', { idx: this.options.plane }, function (err, res) {
            if (!err) {
                global.Data.plane.plane[self.options.plane] = 1;
                global.Data.coin -= self.money
                global.Event.emit('PLANE');
                global.EJMgr.popUI();
                global.Event.emit('COIN');
            }
        })
        if (global.Data.coin < this.money) {
            global.EJMgr.pushUI('Eject/EveryDayGift')
        }else{
            if(global.Data.inviteCount<global.Data.unlock[this.options.plane].invite){
                global.EJMgr.pushUI('inviteReward/inviteReward');
            }
        }
    },

    onClickShare() {
        SoundMgr.playButtonEffect()
        // global.EJMgr.pushUI('inviteReward/inviteReward');
    },
});
